Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-36 dns record lifecycle #66

Merged
merged 3 commits into from
Apr 11, 2024
Merged

GH-36 dns record lifecycle #66

merged 3 commits into from
Apr 11, 2024

Conversation

maksymvavilov
Copy link
Contributor

@maksymvavilov maksymvavilov commented Mar 27, 2024

After applying changes to the DNS provider ruqueue DNS Record for validation; mark the Record as ready only after the validation success.
Also, reconcile records with a default timeout to ensure the validity of the content.

@maksymvavilov maksymvavilov linked an issue Mar 27, 2024 that may be closed by this pull request
4 tasks
@maksymvavilov maksymvavilov force-pushed the GH-36 branch 10 times, most recently from 2c50540 to dcaee02 Compare April 5, 2024 01:20
@maksymvavilov maksymvavilov changed the title [WIP] GH-36 dns record lifecycle GH-36 dns record lifecycle Apr 5, 2024
@maksymvavilov maksymvavilov marked this pull request as ready for review April 5, 2024 01:44
@maksymvavilov maksymvavilov force-pushed the GH-36 branch 2 times, most recently from 5837f6d to 9dc4819 Compare April 5, 2024 12:37
setDNSRecordCondition(dnsRecord, string(conditions.ConditionTypeReady), status, reason, message)
return r.updateStatus(ctx, previous, dnsRecord)
setDNSRecordCondition(dnsRecord, string(v1alpha1.ConditionTypeReady), metav1.ConditionFalse, reason, message)
return r.updateStatus(ctx, previous, dnsRecord, "0s")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of this being a string an being parsed later on. If we have to do it this way, perhaps we could also pull it out to a constant? requeueImmediate or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seemed like that as well for me. Here is the way it looks good to me. Could have those changes sin this PR if you prefer it better. But all of them should land soon so i decided to keep this one as is 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and along with it there would be only one parse call and it is only being set from time.Duration.String() string so we could be sure it will succeed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok in that case I am ok to approve with the improvements that are coming

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, there is no harm in having them here I guess.

// cut off here for the short reconcile loop
requeueIn := validFor
if dnsRecord.Status.ValidFor != "" {
requeueIn, _ = time.ParseDuration(dnsRecord.Status.ValidFor)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shoud we be ignoring the error here? Is it possible we have a bad value?

Copy link
Contributor Author

@maksymvavilov maksymvavilov Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible only if someone goes into the CR and changes values manually. This value is being set by .String() call on the duration struct. In case someone messes up with it will be 0 Duration. Then the logic later on will look like this:

expiryTime := previousReconcileStart.Add(0)
       // new reconcile will always be After expiryTime, so this clause always ends up as false 
	if !generationChanged(dnsRecord) && reconcileStart.Before(&expiryTime) {
               // will not requeue 
		return 0, nil
	}

and we won't use the requeueIn anywhere else so the zero duration doesn't matter.

In other words, we really don't care about an error there - user would need to manually play with it and if they do and set an invalid value we will end up ignoring it

Copy link
Collaborator

@maleck13 maleck13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look pretty good. Main question is around use of strings for time durations.

@maksymvavilov
Copy link
Contributor Author

Added log on wrote counter bump and now there is only one parseDuration call (string that is being parsed from the CR and set only from the time.Duration.String() calls

Merged via the queue into main with commit 0fd59e6 Apr 11, 2024
9 checks passed
}

return nil
return defaultRequeueTime, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: To me the logic around updating the conditions and deciding what this requeue time value should be is not the concern of applyChanges. This should just return an error and a bool to say if it had changes, and wherever this is being called use that info to calculate the status and requeue validation time.

It also looks like you are setting stuff in the status before you even know if it successfully updated or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, a good point. I'll note it and will create a follow-up that, hopefully, won't die forgotten by people.
And I was trying to set the status properly 🤔 like even if we weren't successful in updating i still want the timestamp of the reconciliation that prompted an error or if gen has changed i still want to reset the counter regardless of registry failing to publish the plan 🤔 the questionable is the ValidFor field before the success of applied changes, but one could argue that if everything goes bad with the DNS Provider and we set ValidFor for 5 seconds there will be:

  • a error message saying that "oh, boi, you are messed up"
    or
  • b immediate reconciliation (even when i say not to requeue controller-runtime will requeue reconciliation if there will be an error returned from the .Reconcile() call)

This, actually, is a problem - we want at one point to give up reconciling but return an error, but it would keep reconciling. I opted for just leaving things as is (it would be an edge-ish case) instead of creating silly error assertion. It would do one more tinny loop, won't go into DNS logic and will stop, but that is another story.

But it is still a excelent suggestion, thank you! I guess what I was trying to say - the way it is now should not break anything, but you are correct - there is more elegant way to deal with it

@maksymvavilov maksymvavilov deleted the GH-36 branch May 23, 2024 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-queue validation intermittently
3 participants